﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;

namespace net.notdot.XmlOd {
    public class ArgumentInfo {
        private int pos;
        private Type t;

        public ArgumentInfo(int pos, Type t) {
            this.pos = pos;
            this.t = t;
        }

        public int Position {
            get {
                return pos;
            }
        }

        public Type ParameterType {
            get {
                return t;
            }
        }
    }

    public class Scope {
        private Dictionary<string, object> variables = new Dictionary<string, object>();
        private Dictionary<string, Type> types = new Dictionary<string, Type>();
        private Scope parentScope;

        public Scope(Scope parentScope) {
            this.parentScope = parentScope;
        }

        public Scope() {
            this.parentScope = null;
        }

        public void AddVariable(string name, object var) {
            variables.Add(name, var);
        }

        public object GetVariable(string name) {
            object ret;
            if (variables.TryGetValue(name, out ret))
                return ret;
            if (parentScope != null)
                return parentScope.GetVariable(name);
            return null;
        }

        public void AddType(string name, Type type) {
            types.Add(name, type);
        }

        public Type ResolveType(string p) {
            Type ret;
            if (types.TryGetValue(p, out ret))
                return ret;
            if (parentScope != null)
                return parentScope.ResolveType(p);
            return Type.GetType(p);
        }
    }
}
